﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using XFControls.Utils;
using XFControls.XFPanels.XFPanelItems;
using XFControls;
using System.Drawing;

namespace XFSenseUI.XFItems.SenseControls
{
    public class SenseControlToggle : SenseControl
    {
        private int _height;

        public bool Enabled { get; set; }

        public SenseControlToggle()
        {
            ItemRectangle = new Rectangle();
            _height = -1;
            ItemType = XFItemType.Clickable;
        }

        public override int GetHeight()
        {
            if (_height > -1)
                return _height;

            ItemRectangle = this.GetImageRec("toggle-on");
            _height = ItemRectangle.Height;
            return _height;
        }

        public override void ResetHeight()
        {
            _height = -1;
        }

        public override void ItemPaint(System.Drawing.Graphics g, int x, int y)
        {
            if (Enabled)
                this.DrawUI("toggle-on", g, new Rectangle(x, y, ItemRectangle.Width, ItemRectangle.Height));
            else
                this.DrawUI("toggle-off", g, new Rectangle(x, y, ItemRectangle.Width, ItemRectangle.Height));
        }

        public override XFItemClickResult GetClickResult()
        {
            Enabled = !Enabled;
            return XFItemClickResult.Nothing;
        }
    }
}
